package com.yfp.operation.controller;

import com.yfp.common.core.domain.R;
import com.yfp.common.core.utils.poi.ExcelUtil;
import com.yfp.common.core.web.controller.BaseController;
import com.yfp.common.core.web.page.TableDataInfo;
import com.yfp.common.log.annotation.Log;
import com.yfp.common.log.enums.BusinessType;
import com.yfp.operation.domain.dto.EnteringLogisticsSnDTO;
import com.yfp.operation.domain.dto.MallOrderListDTO;
import com.yfp.operation.domain.vo.MallOrderListVO;
import com.yfp.operation.service.MallOrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 
 * @version 1.0
 * @date 2025-03-05 11:31
 */
@RestController
@RequestMapping("/mallOrder")
@Tag(name = "商城订单")
public class MallOrderController extends BaseController {

    @Resource
    private MallOrderService mallOrderService;


    @GetMapping
    @Operation(summary = "商城订单列表")
    public TableDataInfo<MallOrderListVO> mallOrderList(MallOrderListDTO mallOrderListDTO) {
        startPage();
        List<MallOrderListVO> list = mallOrderService.mallOrderList(mallOrderListDTO);
        TableDataInfo dataTable = getDataTable(list);
        list = mallOrderService.mallOrderListComplement(list);
        dataTable.setRows(list);
        return dataTable;
    }


    @Log(title = "商城订单列表导出", businessType = BusinessType.EXPORT)
    @Operation(summary = "商城订单列表导出")
    @PostMapping("/mallOrderDerive")
    public void mallOrderDerive(HttpServletResponse response, MallOrderListDTO mallOrderListDTO){
        List<MallOrderListVO> list = mallOrderService.mallOrderList(mallOrderListDTO);
        ExcelUtil<MallOrderListVO> util = new ExcelUtil<>(MallOrderListVO.class);
        util.exportExcel(response, list, "商城订单列表导出");
    }


    @PostMapping("/refund")
    @Operation(summary = "商城订单退款")
    public R<Void> mallOrderRefund(@RequestBody List<Long> ids) {
        return mallOrderService.mallOrderRefund(ids);
    }


    @GetMapping("/{id}")
    @Operation(summary = "根据id获取订单信息")
    public R<MallOrderListVO> getByMallOrderId(@PathVariable("id") Long id){
        return R.ok(mallOrderService.getByMallOrderId(id));
    }


    @PostMapping("/enteringLogisticsSn")
    @Operation(summary = "录入快递单号")
    public R<Void> enteringLogisticsSn(@RequestBody EnteringLogisticsSnDTO enteringLogisticsSnDTO){
        mallOrderService.enteringLogisticsSn(enteringLogisticsSnDTO);
        return R.ok();
    }



}
